<?php
include('HTGPage.class.php');
$page = new HTGPage();
/* @var $security HTSecurity */
$security = $page->mySecurity;

if(!($security->isLoggedIn())) {
  $page->redirectTo("login.php?ref=ncaaf");
  die();	
}

$leagueId = 2; //ncaaf league EventType
$picks = $page->myUtils->getAllPicksByLeagueId($leagueId);

@error_log(__FILE__ . ' ' . __LINE__ . " picks: " . array_count_values($picks));

if(!(@array_count_values($picks) > 0)) {
	//TODO automatically create issues and produce the tracking id to it if the users decides to pursue it.
	$page->content .= '<span class="error">We seem to be having some issues finding our picks for ya.  An alert has been sent and we\'re currently looking into it.</span>';
	$page->display();
	die();
}

//****BROWSERS OUTPUT STARTED HERE *****
$page->displayHeader();

//echo '<span class="pageTitle">NFL Picks for: ' . @date('l F jS') . '</span><br />';
echo '<br />';
$lastEventId=false;
$lastPickDate=false;
//loop through the picks
foreach($picks as $pick) {
	$eventId = $pick['e_id'];
	$pickDate = $pick['p_initdate'];
	if($lastEventId == false || $lastEventId != $eventId) { //It's the next post

		if($lastEventId){ //close the previous post
?>
</tbody>
</table>
</td></tr></table>
</div>
<div class="meta">
<p class="credit">Posted by <a href="about.php"> TheGenius</a> @ <?= $lastPickDate ?></p>

<p class="links"><a href="#" class="comments">Comments (0)</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#" class="more">Read more</a></p>
</div>
</div>

<?php 			
		}
		?>


<div class="post" style="width: 583px;">
<div class="title">
<h2><a href="#"><?php echo $pick['e_vis_team']; ?> @ <?= $pick['e_home_team'] ?></a></h2>
<p><?= $pick['e_starttime'] ?></p>

</div>
<div class="entry">
<p><?= $pick['p_text'] ?></p>
</div>
<div class="pickTableDiv"><table class="pickTableContainer"><tr><td class="pickTableIconContainer"><img src="images/thumbs_up.png"/></td><td>
<table class="pickTable">
<thead>
<tr>
<th></th>

<th>Genius Pick</th>
<th>Teams</th>
<th>League</th>
<th>Starts</th>
</tr>
</thead>
<tfoot>

</tfoot>
<tbody>
<tr>
<td></td>
<td><span class="pickTablePic"><?= $pick['p_pick'] ?></span></td>
<td><?= $pick['e_vis_team'] ?> @ <?= $pick['e_home_team'] ?></td>
<td>NFL</td>

<td style="white-space: nowrap;"><?= $pick['e_starttime'] ?></td>
</tr>

<?php 
	} else { //It's a related post
?>
<tr>
<td>@ 1/2</td>
<td><span class="pickTablePic"><?= $pick['p_pick']?></span></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php 	
	} 
	$lastEventId = $eventId;
	$lastPickDate = $pickDate;
}

?>
</tbody>
</table>
</td></tr></table>
</div>
<div class="meta">
<p class="credit">Posted by <a href="about.php">TheGenius</a> @ <?= $lastPickDate ?> PDT</p>

<p class="links"><a href="#" class="comments">Comments (0)</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#" class="more">Read more</a></p>
</div>
</div>

<?php 
$page->displayFooter();
?>